#pragma once
#include "PropertyHelper.h"
#include <QImage>
#include <QQuickItem>
class YUVItem : public QQuickItem
{
	Q_OBJECT

	AUTO_PROPERTY(QUrl, source, {})
	AUTO_PROPERTY(int64_t, bitrate, 0)

	using Super = QQuickItem;

	QML_NAMED_ELEMENT(RectangleItem)
public:
	YUVItem(QQuickItem* parent = nullptr);
	virtual ~YUVItem();

protected:
	virtual QSGNode* updatePaintNode(QSGNode*, UpdatePaintNodeData*) override;
protected slots:
	void onTimeout();
	void onSourceChanged();

private:
	bool	   mGeometryChanged = true;
	bool	   mSourceChanged	= true;
	bool	   mBitrateChanged	= true;
	QTimer*	   mTimer			= nullptr;
	QByteArray mData;
	int		   mDataWidth  = 0;
	int		   mDataHeight = 0;
	int		   mDataOffset = 0;
	QByteArray mDataY;
	QByteArray mDataU;
	QByteArray mDataV;
	bool	   mYUVChanged = false;
};
